<template>
	<view class="good-project-view">
		<view class="good-project-list" v-for="item in goodProjectArr" :key="item.id">
			<project-item :info="item"></project-item>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodProjectArr: [],
				page: 1,
				total: 0
			};
		},
		onLoad() {
			this.getGoodProject()
		},
		onPullDownRefresh() {
			this.page = 1
			this.getGoodProject()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1500)
		},
		onReachBottom() {
			if (this.list.length < this.total) {
				this.page++
				this.getGoodProject()
			} else {
				this.$api.showError('没有更多了~')
			}
		},
		methods: {
			// 获取精选项目
			getGoodProject() {
				this.$api
					.requst('/gwc/projects', {
						type: 1,
						page: this.page
					})
					.then((res) => {
						this.total = res.total
						if (this.page === 1) {
							this.goodProjectArr = res.data
						} else {
							res.data.forEach(item => {
								this.goodProjectArr.push(item)
							})
						}
					})
			},
		}
	}
</script>

<style lang="scss">
	.good-project-view {
		padding-bottom: 30rpx;
		box-sizing: border-box;

		.good-project-list {
			margin: 16rpx 24rpx 0;
		}

		.good-project-list:first-child {
			margin-top: 24rpx;
		}
	}
</style>